﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Catalogo.Portable.ViewModel;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Catalogo.Portable.ViewModel.Messages;

namespace Catalogo.WindowsPhone.Views
{
    public partial class CategoriaPage : PhoneApplicationPage
    {
        public CategoriaPageViewModel ViewModel
        {
            get
            {
                return DataContext as CategoriaPageViewModel;
            }
        }

        public CategoriaPage()
        {
            InitializeComponent();
        }
 
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            var idCategoria = NavegarParaPaginaMessageHandler.ObterParametro(e.Uri);
            if (ViewModel == null)
            {
                DataContext = new CategoriaPageViewModel();
                ViewModel.Messenger.Subscribe<NavegarParaPagina>(NavegarParaPaginaMessageHandler.NavegarParaPagina);
                await ViewModel.LoadAsync(idCategoria);
                Panorama.Background = new ImageBrush() { ImageSource = new BitmapImage(new Uri(ViewModel.Empresa.ImageUrl)), Stretch = Stretch.UniformToFill };
            }
        }
    }
}